package myzzyl.controller;



import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import myzzyl.domain.dto.NursingPlanDto;
import myzzyl.domain.pojo.NursingPlan;
import myzzyl.domain.vo.NursingPlanVo;
import myzzyl.domain.vo.NursingProjectVo;
import myzzyl.response.BaseResponse;
import myzzyl.response.PageResponse;
import myzzyl.service.NursingPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Tag(name = "护理计划相关")
@Slf4j
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 分页获取所有护理计划
     */
    @GetMapping("/search")
    public BaseResponse<PageResponse<NursingPlanVo>> getAllByFloorId(
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        log.info("分页获取所有护理计划:{}, {}, {}, {}", name, status, pageNum, pageSize);
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getAll(name, status, pageNum, pageSize);
        return BaseResponse.success(pageResponse);
    }

    /**
     * 获取护理计划详情
     */
    @GetMapping("/{id}")
    public BaseResponse<NursingPlanVo> getInfo(@PathVariable Integer id) {
        log.info("获取护理计划详情:{}", id);
        return BaseResponse.success(nursingPlanService.getInfo(id));
    }


    /**
     * 新增护理计划
     */
    @PostMapping
    public BaseResponse<Boolean> add(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("新增护理计划:{}", nursingPlanDto);
        return nursingPlanService.add(nursingPlanDto) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }


    /**
     * 编辑护理计划
     */
    @PutMapping
    public BaseResponse<Boolean> edit(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("编辑护理计划:{}", nursingPlanDto);
        return nursingPlanService.edit(nursingPlanDto) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 删除护理计划
     */
    @DeleteMapping("/{id}")
    public BaseResponse<Boolean> remove(@PathVariable Integer id) {
        log.info("删除护理计划:{}", id);
        return nursingPlanService.deleteNursingPlanById(id) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 启用或禁用护理计划
     */
    @PutMapping("/{id}/status/{status}")
    public BaseResponse<Boolean> enableOrDisableNursingPlan(@PathVariable("id") Integer id,
                                                            @PathVariable("status") Integer status) {
        log.info("启用或禁用护理计划:{}, {}", id, status);
        return nursingPlanService.enableOrDisableNursingPlan(id, status) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 获取所有护理计划
     */
    @GetMapping
    public BaseResponse<List<NursingPlanVo>> listAll() {
        log.info("获取所有护理计划");
        return BaseResponse.success(nursingPlanService.listAll());
    }

}
